#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


class Solution {
public:
    int sumOddLengthSubarrays(vector<int>& arr) {
        int sum = 0;
        /* 计算前缀和 */
        vector<int> arrSum(arr.size() + 1, 0);
        for (int idx = 1; idx < arrSum.size(); idx++) {
            arrSum[idx] = arr[idx -1] + arrSum[idx -1];
            /* 奇数长度数组相加 */
            int n = 1;
            int num =  idx - (2 * n - 1);
            while (num >= 0) {
                sum += arrSum[idx] - arrSum[num];
                n++;
                num =  idx - (2 * n - 1);
            }
        }
        return sum;
    }
};

int main()
{
    vector<int> vt{1,4,2,5,3};
    Solution s;
    cout << s.sumOddLengthSubarrays(vt) << endl;
    return 0;
}